package com.example.hangzhou.welbeing.mytestdemoapp.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.widget.Button;
import android.widget.TextView;

import com.example.hangzhou.welbeing.mytestdemoapp.R;
import com.example.hangzhou.welbeing.mytestdemoapp.animation.animationActivity.TraditionalAnimationActivity;
import com.example.hangzhou.welbeing.mytestdemoapp.bean.Mydate;

import java.util.ArrayList;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;
import rx.Observable;
import rx.android.schedulers.AndroidSchedulers;
import rx.functions.Action1;
import rx.functions.Func1;
import rx.schedulers.Schedulers;

/**
 * 杭州惟君医疗科技有限公司09
 * Created by 20433 on 2018/4/3
 *
 * @desc 东风山河绿，春已不折柳，繁花看不尽，处处惹人留
 * @desc 佛祖镇楼，bug辟容易
 */

public class ObserverActivity extends AppCompatActivity {
    @Bind(R.id.textView4)
    TextView textView4;
    @Bind(R.id.button4)
    Button button4;
    private int i = 1;
    private ArrayList<Mydate> mlist = new ArrayList<>();
    private ArrayList<Integer> mdate = new ArrayList<>();

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_observer);
        ButterKnife.bind(this);
        mdate.add(1);
        mdate.add(2);
        mdate.add(3);
        mdate.add(4);
        mdate.add(5);
        mdate.add(6);
        mdate.add(7);
        mlist.add(new Mydate(1,"甲方的",mdate));
        mlist.add(new Mydate(2,"乙方的",mdate));
        mlist.add(new Mydate(3,"丙方的",mdate));
        mlist.add(new Mydate(4,"丁方的",mdate));
        mlist.add(new Mydate(5,"三方的",mdate));
        mlist.add(new Mydate(6,"死方的",mdate));
        mlist.add(new Mydate(7,"死方的",mdate));
        mlist.add(new Mydate(8,"死方的",mdate));
        mlist.add(new Mydate(9,"死方的",mdate));
        mlist.add(new Mydate(10,"死方的",mdate));
        mlist.add(new Mydate(11,"死方的",mdate));

    }

    @OnClick(R.id.button4)
    public void onViewClicked() {
        Observable.from(mlist)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .filter(new Func1<Mydate, Boolean>() {  //对 mlist 过滤
                    @Override
                    public Boolean call(Mydate mydate) {
                        return mydate.getInteger()==2;
                    }
                })
                .observeOn(Schedulers.newThread())
                .flatMap(new Func1<Mydate, Observable<Integer>>() {  //对 mdate 遍历
                    @Override
                    public Observable<Integer> call(Mydate mydate) {
                        return Observable.from(mydate.getMlist());
                    }
                })
                .observeOn(AndroidSchedulers.mainThread())
                .filter(new Func1<Integer, Boolean>() {  //对 Integer 过滤
                    @Override
                    public Boolean call(Integer integer) {
                        return integer==3;
                    }
                })
                .map(new Func1<Integer, String>() { //对 Integer 转换成 String
                    @Override
                    public String call(Integer integer) {
                        return integer+"那附近";
                    }
                })
                .subscribe(new Action1<String>() {
                    @Override
                    public void call(String s) {
                        Intent intent_07 = new Intent(ObserverActivity.this, TraditionalAnimationActivity.class);
                        startActivity(intent_07);
                        overridePendingTransition(R.anim.slide_right_in, R.anim.slide_left_out);
                    }
                }, new Action1<Throwable>() {
                    @Override
                    public void call(Throwable throwable) {

                    }
                });

    }
}
